package com.ziytek.web.citizen;

import com.ziytek.web.citizen.constant.ServerConstant;
import com.ziytek.web.citizen.util.PortCheckerUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.swing.*;

/**
 * @author fenghx
 * @version v1.0
 * @className Application
 * @descripton 启动项 @EnableTransactionManagement //开始事务
 * @date 2023/4/10 18:16
 **/
@Slf4j
@EnableAsync
@EnableScheduling
@ServletComponentScan
@EnableTransactionManagement
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class Application {
    public static void main(String[] args) {
        // 使用端口占用情况,检查程序是否运行
        if (PortCheckerUtil.isPortInUse(ServerConstant.PORT_TCP) && PortCheckerUtil.isPortInUse(ServerConstant.PORT_SERVER)) {
            log.info("程序已运行,请勿重复启动!");
            // 弹出窗口 提示
            JOptionPane.showMessageDialog(null, "程序已运行,请勿重复启动!");
            return;
        }

        SpringApplication app = new SpringApplication(Application.class);
        // 生成PID文件到项目根目录
        app.addListeners(new ApplicationPidFileWriter("application.pid"));
        app.run(args);
    }
}
